package com.leyou.config;

import com.leyou.utils.RsaUtils;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

import javax.annotation.PostConstruct;
import java.security.PrivateKey;
import java.security.PublicKey;

@Data
@ConfigurationProperties(prefix = "my.jwt")
public class JwtProperties {

    String pubKeyPath;
    String priKeyPath;
    PublicKey publicKey;
    PrivateKey privateKey;
    User user = new User();

    @Data
    public class User {
        int expire;
        String cookieName;
        String cookieDomain;
    }

    /**
     * 创建对象后执行的方法
     * 使用PostConstruct注解
     */
    @PostConstruct
    public void initKey() {
        try {
            publicKey = RsaUtils.getPublicKey(pubKeyPath);
            privateKey = RsaUtils.getPrivateKey(priKeyPath);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
